#ifndef __KEYRECOMMANDER_H__
#define __KEYRECOMMANDER_H__
#include"CandidateResult.h"
#include"TcpConnection.h"
#include"MyRedis.h"
#include<queue>
#include<vector>
#include<set>
using std::priority_queue;
using std::vector;
using std::set;
class Comp{
public:
    bool operator()(CandidateResult &lhs,CandidateResult &rhs)
    {
        if((lhs._dist > rhs._dist) || (lhs._dist == rhs._dist && lhs._freq < rhs._freq) || (lhs._dist == rhs._dist && lhs._freq == rhs._freq && lhs._word > rhs._word)) {
            return true;
        }
        else {
            return false;
        }
    }
};

class KeyRecommander{
private:
    TcpConnectionPtr _con;
    priority_queue<CandidateResult,vector<CandidateResult>,Comp> _resultQue;

public:
    KeyRecommander(const string &dictEn,const string &dictZh, const string &indexEn, const string &indexZh);
    ~KeyRecommander();
    string execute(string &Msg);
private:
    void queryIndexTable(string &Msg);
    void statistic(string &Msg,set<int> &iset);
    //jisuan
    int distance(string &Msg,const string &rhs);
    string response(string &Msg);

};

#endif